package com.shopping.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.shopping.bean.User;

/**
 * @author zjh
 *
 */
@WebServlet("/user.do")
public class GoodsMsgServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = (User) request.getSession().getAttribute("loginUser");
		ObjectMapper om = new ObjectMapper();
		String address = "请填写地址";
		if(user.getAddress() != null) {
			response.setCharacterEncoding("UTF-8"); //设置 后端给前端传回的编码格式为utf-8
			response.setContentType("application/json");// 后端告知前端 返回的数据 是 json格式(不是html /css)
			response.getWriter().print(om.writeValueAsString(user.getAddress()));
		}else {
			response.setCharacterEncoding("UTF-8"); //设置 后端给前端传回的编码格式为utf-8
			response.setContentType("application/json");// 后端告知前端 返回的数据 是 json格式(不是html /css)
			response.getWriter().print(om.writeValueAsString(address));
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
